<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller 
{
	/**
    *自动执行    简单登陆权限  验证
    */
    public function _initialize()
    {
        
        $path = CONTROLLER_NAME.'/'.ACTION_NAME;
        if (in_array($path, C('AUTH_PATH'))) {
            //判断登陆否
            if (!$_SESSION['phone']) {

                $this->error('非法访问 跳转中...',U('index/index'));
            }
            //浏览记录 记录入库
            $this->history(); 
        }else {
            //浏览记录 记录入库
            $this->history(); 
        }
    }

    /**
    *纪录所有历史浏览记录
    *$url [REQUEST_URI] => /fly/index.php/admin/level/index.html 
    *$ip = get_client_ip();
    *
    */
    public function history()
    {
      $data['phone'] = $_SESSION['phone']?$_SESSION['phone']:'游客';
      $data['client_ip'] = get_client_ip();
      $data['url'] = $_SERVER['REQUEST_URI'];
      $data['access_time'] = time();
      //入库
      M('history')->add($data);
    }


    //信息显示
    function public_xianshi()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);
        //授课城市显示
        $city_info = M('city')->where('parent_id=0')->select();
        $this->assign('city_info',$city_info);

        
    }


    /**
    *自动把字段 加多少 
    *表名$table 字段$field key $id  加多少$num
    */
    public function auto_num($table,$field,$id,$num)
    {
        $sql = 'update '.$table.' set '.$field.'='.$field.'+'.$num. ' where id='.$id;
        $row = M()->execute($sql);
        return $row;

    }





}